//
//  LRTabBarViewController.m
//  本地生活圈
//
//  Created by admin on 15/8/9.
//  Copyright (c) 2015年 懒人. All rights reserved.
//

#import "LRTabBarViewController.h"
#import "LRHomeViewController.h"
#import "LRNewsViewController.h"
#import "LRCircleViewController.h"
#import "LRToolsViewController.h"

#define kPopViewHeight 44

@interface LRTabBarViewController ()

/**
 *  当前选中的按钮
 */
@property (nonatomic, strong) UIButton *selectBtn;
@end

@implementation LRTabBarViewController

- (UIView *)tabBarView
{
    if (!_tabBarView)
    {
        _tabBarView = [[UIView alloc]initWithFrame:CGRectMake(0, kUIScreenH - kTabBarHeight, kUIScreenW, kTabBarHeight)];
        [self.view addSubview:self.tabBarView];
    }
    return _tabBarView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];

    self.tabBarView.backgroundColor = [UIColor redColor];
    
    // 添加5个item
    CGFloat itemW = kUIScreenW / 5;
    CGFloat itemH = kTabBarHeight;
    for (int i = 0; i < 5; i++)
    {
        UIButton *item = [[UIButton alloc]initWithFrame:CGRectMake(itemW * i, 0, itemW, itemH)];
        
        NSString *imgNameNor = [NSString stringWithFormat:@"home_%d",i ];
        NSString *imgNameSel = [NSString stringWithFormat:@"home_%d_pressed",i];
        
        [item setBackgroundImage:[UIImage imageNamed:imgNameNor] forState:UIControlStateNormal];
        [item setBackgroundImage:[UIImage imageNamed:imgNameSel] forState:UIControlStateSelected];
        
        [item addTarget:self action:@selector(changeVc:) forControlEvents:UIControlEventTouchUpInside];
        
        item.tag = i;
        
        if (i == 0)
        {
            [self changeVc:item];
        }
        
        [self.tabBarView addSubview:item];
    }
    
    // 创建popview
    self.popView = [[UIView alloc]initWithFrame:CGRectMake(0, kUIScreenH - kTabBarHeight - kPopViewHeight, kUIScreenW, kPopViewHeight)];
    
    UIImageView *imgBg = [[UIImageView alloc]initWithFrame:self.popView.bounds];
    
    imgBg.image = [UIImage imageNamed:@"home_topbar"];
    
    [self.popView addSubview:imgBg];
    
    [self.view addSubview:self.popView];
    
    self.popView.hidden = YES;
    
    // 隐藏自身的tabBarView
//    self.tabBar.alpha = 0;
    self.tabBar.hidden = YES;
    
//    CGRect rect = [UIScreen mainScreen].bounds;
//    LRLog(@"%@",NSStringFromCGRect(rect));

}


- (void)changeVc:(UIButton *)btn
{
    self.selectBtn.selected = NO; // 取消上一个选中按钮状态
    
    btn.selected = YES;
    
    self.selectBtn = btn; // 赋值给当前按钮
    
    // 如果是第五个按钮
    self.popView.hidden = btn.tag != 4;
   
    self.selectedIndex = btn.tag;
}







@end
